package com.atguigui.leetcode1;

/**
 * 1653.使字符串平衡的最少删除次数
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/3/6 9:28
 */
public class P1653MinimumDeletionsToMakeStringBalanced {

    public static void main(String[] args) {
        Solution solution = new P1653MinimumDeletionsToMakeStringBalanced().new Solution();
        // TO TEST
    }


    class Solution {
        public int minimumDeletions(String s) {

            int f = 0, cntB = 0;
            for (char c : s.toCharArray()) {
                if (c == 'b') {
                    ++cntB;
                } else {
                    f = Math.min(f + 1, cntB);
                }

            }


            return f;
        }
    }
}
